﻿<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:loc="clr-namespace:WpfApplication1"
        xmlns:cnv="clr-namespace:WpfApplication1.Converters"
        Title="MainWindow"
        Height="350"
        Width="525"
        Name="MainWindow1"
        FlowDirection="RightToLeft">
    <Window.Resources>

        <PathGeometry x:Key="AccountModule">F1 M 38.7916,15.8334C 40.5405,15.8334 40.375,17.2511 40.375,19L 40.4832,22.422L 58.8399,27.5931L 58.0738,30.6657L 56.0774,30.168L 64.9166,47.5C 64.9166,50.5606 59.8717,53.0417 54.625,53.0417C 49.3783,53.0417 44.3333,50.5606 44.3333,47.5L 52.3887,29.2483L 40.6112,26.3118L 41.5394,53.9324C 47.6545,54.3801 52.25,56.2923 52.25,58.5833L 25.3333,58.5833C 25.3333,56.2923 29.9288,54.3801 36.0439,53.9324L 37.1289,25.4436L 23.8151,22.1241L 31.6666,40.375C 31.6666,43.4356 26.6217,45.9167 21.375,45.9167C 16.1283,45.9167 11.0833,43.4356 11.0833,40.375L 20.1264,21.2044L 18.13,20.7066L 18.8961,17.634L 37.2057,22.0007L 37.2083,19C 37.2083,17.2511 37.0427,15.8334 38.7916,15.8334 Z M 61.2191,47.5L 55.4166,33.1384L 55.4166,47.5L 61.2191,47.5 Z M 48.0308,47.5L 53.8333,47.5L 53.8333,33.1384L 48.0308,47.5 Z M 27.9691,40.3751L 22.1666,26.0135L 22.1666,40.3751L 27.9691,40.3751 Z M 14.7808,40.3751L 20.5833,40.3751L 20.5833,26.0134L 14.7808,40.3751 Z</PathGeometry>
        <PathGeometry x:Key="WarehouseModule">F1 M 28.5,20.5833L 47.5,20.5833L 47.5,23.75L 28.5,23.75L 28.5,20.5833 Z M 49.0833,31.6667L 64.9166,31.6667L 64.9166,34.8334L 49.0833,34.8334L 49.0833,31.6667 Z M 28.5,25.3334L 34.8333,25.3334L 41.1666,25.3334L 47.5,25.3334L 47.5,52.25L 41.1666,52.25L 41.1666,42.75L 34.8333,42.75L 34.8333,52.25L 28.5,52.25L 28.5,25.3334 Z M 49.0833,52.25L 49.0833,36.4167L 53.8333,36.4167L 60.1666,36.4167L 64.9166,36.4167L 64.9166,52.25L 60.1666,52.25L 60.1666,44.3333L 53.8333,44.3333L 53.8333,52.25L 49.0833,52.25 Z M 11.0833,52.25L 11.0833,44.3333L 11.0833,41.1667L 19.7917,34.8334L 26.9167,41.1667L 26.9167,44.3333L 26.9167,52.25L 22.1667,52.25L 22.1667,44.3333L 15.8333,44.3333L 15.8333,52.25L 11.0833,52.25 Z M 19.7916,29.6875L 26.9166,36.0209L 26.9166,39.1875L 19.7916,32.8542L 9.49999,40.375L 9.49999,37.2084L 19.7916,29.6875 Z</PathGeometry>
        <PathGeometry x:Key="PointOfSaleModule">F1 M 22.3908,33.9299L 34.0851,45.6243L 29.7767,49.9327L 18.0823,38.2384L 22.3908,33.9299 Z M 17.1591,37.3152L 14.6971,35.3402C 13.9076,34.5507 14.2153,32.873 15.0049,32.0835L 16.2359,30.8525C 17.0254,30.063 18.5238,29.7552 19.3133,30.5447L 21.4675,33.0067L 17.1591,37.3152 Z M 35.9418,52.3947L 30.6999,50.856L 35.0084,46.5475L 36.4473,51.8893L 35.9418,52.3947 Z M 39.9167,15.8333C 42.1028,15.8333 44.25,17.8139 44.25,20L 44,21L 56,21L 56,57L 24,57L 24,47.75L 27,50.75L 27,54L 53,54L 53,24L 47.5,24L 49.5,28L 30.5,28L 32.5,24L 27,24L 27,35.5L 24,32L 24,21L 36,21L 35.75,20C 35.75,17.8139 37.7305,15.8333 39.9167,15.8333 Z M 39.9166,18.2084C 39.0422,18.2084 38,18.8756 38,19.75C 38,20.0384 38.3653,20.7671 38.5,21L 41.5,21C 41.6347,20.7671 42,20.0384 42,19.75C 42,18.8756 40.7911,18.2084 39.9166,18.2084 Z</PathGeometry>
        <PathGeometry x:Key="AssetsModule">F1 M 44.3333,30.0833L 57,30.0833L 57,57L 44.3333,57L 44.3333,30.0833 Z M 46.3125,35.2292L 46.3125,38L 49.0833,38L 49.0833,35.2292L 46.3125,35.2292 Z M 52.25,35.2292L 52.25,38L 55.0208,38L 55.0208,35.2292L 52.25,35.2292 Z M 46.3125,39.9792L 46.3125,42.75L 49.0833,42.75L 49.0833,39.9792L 46.3125,39.9792 Z M 52.25,39.9792L 52.25,42.75L 55.0208,42.75L 55.0208,39.9792L 52.25,39.9792 Z M 46.3125,44.7292L 46.3125,47.5L 49.0833,47.5L 49.0833,44.7292L 46.3125,44.7292 Z M 52.25,44.7292L 52.25,47.5L 55.0208,47.5L 55.0208,44.7292L 52.25,44.7292 Z M 46.3125,49.4792L 46.3125,52.25L 49.0833,52.25L 49.0833,49.4792L 46.3125,49.4792 Z M 52.25,49.4792L 52.25,52.25L 55.0208,52.25L 55.0208,49.4792L 52.25,49.4792 Z M 23.75,25.3333L 25.3333,22.1667L 26.9167,22.1667L 26.9167,18.2084L 28.5,18.2084L 28.5,22.1667L 31.6667,22.1667L 31.6667,18.2084L 33.25,18.2084L 33.25,22.1667L 34.8333,22.1667L 36.4167,25.3333L 36.4167,34.8334L 38.7917,34.8333L 41.1667,37.2083L 41.1667,57L 19,57L 19,37.2083L 21.375,34.8333L 23.75,34.8334L 23.75,25.3333 Z M 25.7291,27.3125L 25.7291,30.0834L 28.1041,30.0834L 28.1041,27.3125L 25.7291,27.3125 Z M 32.0625,27.3125L 32.0625,30.0834L 34.4375,30.0834L 34.4375,27.3125L 32.0625,27.3125 Z M 25.7291,32.0625L 25.7291,34.8334L 28.1041,34.8334L 28.1041,32.0625L 25.7291,32.0625 Z M 32.0625,32.0625L 32.0625,34.8334L 34.4375,34.8334L 34.4375,32.0625L 32.0625,32.0625 Z M 30.875,39.9792L 28.8958,39.9792L 28.8958,42.75L 30.875,42.75L 30.875,39.9792 Z M 24.5416,39.9792L 24.5416,42.75L 26.9166,42.75L 26.9166,39.9792L 24.5416,39.9792 Z M 36.0208,39.9792L 33.25,39.9792L 33.25,42.75L 36.0208,42.75L 36.0208,39.9792 Z M 30.875,44.7292L 28.8958,44.7292L 28.8958,47.5L 30.875,47.5L 30.875,44.7292 Z M 26.9166,44.7292L 24.5416,44.7292L 24.5416,47.5L 26.9166,47.5L 26.9166,44.7292 Z M 36.0208,44.7292L 33.25,44.7292L 33.25,47.5L 36.0208,47.5L 36.0208,44.7292 Z M 30.875,49.4792L 28.8958,49.4792L 28.8958,52.25L 30.875,52.25L 30.875,49.4792 Z M 26.9166,49.4792L 24.5416,49.4792L 24.5417,52.25L 26.9167,52.25L 26.9166,49.4792 Z M 36.0208,49.4792L 33.25,49.4792L 33.25,52.25L 36.0208,52.25L 36.0208,49.4792 Z</PathGeometry>

        <SolidColorBrush x:Key="ModulerItemBackgroundHover">#FF292929</SolidColorBrush>
        <SolidColorBrush x:Key="ModulerItemForegroundHover">#FF353535</SolidColorBrush>
        <SolidColorBrush x:Key="ModulerItemBackgroundSelected">#FF292929</SolidColorBrush>
        <SolidColorBrush x:Key="ModulerItemForegroundSelected">#FFFFFFFF</SolidColorBrush>
        <SolidColorBrush x:Key="ModulerBackground">#FF353535</SolidColorBrush>
        <SolidColorBrush x:Key="ModulerForeground">#FF999999</SolidColorBrush>

        <Style x:Key="ComboElementStyle"
               TargetType="ComboBox">
            <Setter Property="ItemsSource"
                    Value="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=DataContext.Accounts}" />
            <Setter Property="DisplayMemberPath"
                    Value="AccountName" />
            <Setter Property="SelectedValuePath"
                    Value="AccountID" />
        </Style>

        <Style x:Key="ModulerStyle"
               TargetType="ListBox">
            <Setter Property="Background"
                    Value="{StaticResource ModulerBackground}" />
            <Setter Property="Foreground"
                    Value="{StaticResource ModulerForeground}" />
            <Setter Property="BorderThickness"
                    Value="0" />
            <Setter Property="ScrollViewer.HorizontalScrollBarVisibility"
                    Value="Disabled" />
            <Setter Property="Margin"
                    Value="0" />
            <Setter Property="Padding"
                    Value="0" />
            <Setter Property="FocusVisualStyle"
                    Value="{x:Null}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBox">
                        <Border Background="{TemplateBinding Background}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                Padding="0">
                            <ScrollViewer Padding="0"
                                          Focusable="False">
                                <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                            </ScrollViewer>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="ItemContainerStyle">
                <Setter.Value>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="Background"
                                Value="{StaticResource ModulerBackground}" />
                        <Setter Property="Foreground"
                                Value="{StaticResource ModulerForeground}" />
                        <Setter Property="BorderThickness"
                                Value="0" />
                        <Setter Property="Margin"
                                Value="0" />
                        <Setter Property="Padding"
                                Value="0" />
                        <Setter Property="FocusVisualStyle"
                                Value="{x:Null}" />
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="ListBoxItem">
                                    <Border Name="Bd"
                                            Background="Transparent">
                                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                                    </Border>

                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsMouseOver"
                                                 Value="true">
                                            <Setter TargetName="Bd"
                                                    Property="Background"
                                                    Value="{DynamicResource ModulerItemBackgroundHover}" />
                                            <Setter Property="Foreground"
                                                    Value="{DynamicResource ModulerItemForegroundHover}" />
                                        </Trigger>
                                        <Trigger Property="IsSelected"
                                                 Value="true">
                                            <Setter TargetName="Bd"
                                                    Property="Background"
                                                    Value="{DynamicResource ModulerItemBackgroundSelected}" />
                                            <Setter Property="Foreground"
                                                    Value="{DynamicResource ModulerItemForegroundSelected}" />
                                            <Setter Property="FontWeight"
                                                    Value="Bold" />
                                        </Trigger>
                                        <Trigger Property="IsEnabled"
                                                 Value="false">
                                            <Setter Property="Foreground"
                                                    Value="{DynamicResource ItemTextDisabled}" />
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </Setter.Value>
            </Setter>
        </Style>

    </Window.Resources>
    <Grid>
        <Border Margin="248,10,26,309">
            <Border.Background>
                <LinearGradientBrush EndPoint="0,.5" StartPoint="1,.5">
                    <GradientStop Color="White"/>
                    <GradientStop Color="Silver" Offset="0.8"/>
                    <GradientStop Color="Silver" Offset="0.2"/>
                    <GradientStop Color="White" Offset="1"/>
                </LinearGradientBrush>
            </Border.Background>
        </Border>
        <DataGrid ItemsSource="{Binding Path=Lines}"
                  AutoGenerateColumns="False"
                  Margin="0,85,53,0"
                  VerticalAlignment="Top"
                  Height="125"
                  Name="dgLines"
                  PreviewKeyDown="OnKeyDown"
                  CurrentCellChanged="OnCurrentCellChanged"
                  HorizontalAlignment="Right"
                  Width="283">

            <DataGrid.RowStyle>
                <Style TargetType="DataGridRow">
                    <Style.Triggers>
                        <Trigger Property="Validation.HasError"
                                 Value="True">

                            <Setter Property="ToolTip"
                                    Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.RowStyle>

            <DataGrid.RowValidationRules>
                <loc:RowDataInfoValidationRule ValidationStep="UpdatedValue" />
            </DataGrid.RowValidationRules>

            <DataGrid.RowHeaderTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Converter={cnv:RowToIndexConverter}}" />
                </DataTemplate>
            </DataGrid.RowHeaderTemplate>

            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding Path=Debit, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                    Header="مدين"
                                    Width="15*" />

                <DataGridTextColumn Binding="{Binding Path=Credit, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                    Header="دائن"
                                    Width="15*" />

                <DataGridComboBoxColumn Header="الحساب"
                                        DisplayMemberPath="AccountName"
                                        SelectedItemBinding="{Binding Path=Account, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                        SelectedValueBinding="{Binding Path=AccountID, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                        ElementStyle="{StaticResource ComboElementStyle}"
                                        EditingElementStyle="{StaticResource ComboElementStyle}" />

                <DataGridTextColumn Binding="{Binding Path=Description, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                    Header="الوصف"
                                    Width="50*" />
            </DataGrid.Columns>
        </DataGrid>

        <Button Content="Button"
                HorizontalAlignment="Left"
                Margin="389,240,0,0"
                VerticalAlignment="Top"
                Command="{Binding Path=DebugCommand}"
                Width="75" />
        <loc:AccountSelector HorizontalAlignment="Left"
                             Margin="181,215,0,0"
                             VerticalAlignment="Top"
                             DisplayMemberPath="AccountName"
                             ItemsSource="{Binding Path=Accounts}"
                             Width="161" />

        <ListBox Style="{StaticResource ModulerStyle}"
                 Margin="0,0,387,0">
            <ListBoxItem Height="34"
                         Margin="0,0,0,5">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="32" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <Path Grid.Column="0"
                          Stretch="Uniform"
                          Data="{DynamicResource AccountModule}"
                          Fill="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBoxItem}, Path=Foreground}" />

                    <TextBlock Grid.Column="1"
                               VerticalAlignment="Center"
                               Margin="5,0,0,0"
                               Text="المحــــــــاسبة"
                               FontFamily="القلم ــ المهند عريض"
                               FontSize="20" />
                </Grid>
            </ListBoxItem>
            <ListBoxItem Height="34"
                         Margin="0,0,0,5">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="32" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <Path Grid.Column="0"
                          Stretch="Uniform"
                          Data="{DynamicResource WarehouseModule}"
                          Fill="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBoxItem}, Path=Foreground}" />

                    <TextBlock Grid.Column="1"
                               VerticalAlignment="Center"
                               Margin="5,0,0,0"
                               Text="المستودعات"
                               FontFamily="القلم ــ المهند عريض"
                               FontSize="20" />
                </Grid>
            </ListBoxItem>
            <ListBoxItem Height="34"
                         Margin="0,0,0,5">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="32" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <Path Grid.Column="0"
                          Stretch="Uniform"
                          Data="{DynamicResource PointOfSaleModule}"
                          Fill="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBoxItem}, Path=Foreground}" />

                    <TextBlock Grid.Column="1"
                               VerticalAlignment="Center"
                               Margin="5,0,0,0"
                               Text="الفواتـــيـــــر"
                               FontFamily="القلم ــ المهند عريض"
                               FontSize="20" />
                </Grid>
            </ListBoxItem>
            <ListBoxItem Height="34"
                         Margin="0,0,0,5">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="32" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <Path Grid.Column="0"
                          Stretch="Uniform"
                          Data="{DynamicResource AssetsModule}"
                          Fill="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBoxItem}, Path=Foreground}" />

                    <TextBlock Grid.Column="1"
                               VerticalAlignment="Center"
                               Margin="5,0,0,0"
                               Text="الأصـــــــــول"
                               FontFamily="القلم ــ المهند عريض"
                               FontSize="20" />
                </Grid>
            </ListBoxItem>
        </ListBox>
        <Border Background="Azure" HorizontalAlignment="Left" Height="32" Margin="263,261,0,0" VerticalAlignment="Top" Width="49"
                     MouseEnter="UserControl_MouseEnter">
            <Border.Style>
                <Style TargetType="Border">
                    <Style.Triggers>
                        <EventTrigger RoutedEvent="Border.MouseEnter">
                            <BeginStoryboard>
                                <Storyboard Storyboard.TargetProperty="Background.Color">
                                    <ColorAnimationUsingKeyFrames BeginTime="00:00:00">
                                        <LinearColorKeyFrame Value="Red" KeyTime="0:0:0" />
                                    </ColorAnimationUsingKeyFrames>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                        <EventTrigger RoutedEvent="Border.MouseLeave">
                            <BeginStoryboard >
                                <Storyboard Storyboard.TargetProperty="Background.Color">
                                    <ColorAnimationUsingKeyFrames BeginTime="00:00:00">
                                        <LinearColorKeyFrame Value="Black" KeyTime="0:0:0" />
                                    </ColorAnimationUsingKeyFrames>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </Style.Triggers>
                </Style>
            </Border.Style>
        </Border>
    </Grid>
</Window>
